package org.huyue.huyuexia.controller;

import lombok.extern.slf4j.Slf4j;
import org.huyue.huyuexia.pojo.Article;
import org.huyue.huyuexia.pojo.Query.ArticleQueryParam;
import org.huyue.huyuexia.service.ArticleService;
import org.huyue.huyuexia.util.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping
    public Result findAll(ArticleQueryParam articleQueryParam) {
        log.info("查询所有文章信息");
        return  Result.success(articleService.findAll(articleQueryParam));
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        log.info("根据id查询文章信息");
        return  Result.success(articleService.findById(id));
    }

    @PostMapping
    public Result save(@RequestBody Article article) {
        articleService.save(article);
        return  Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Article article) {
        articleService.update(article);
        return  Result.success();
    }


}
